package com.atguigu.gmall.order.config;

import com.atguigu.gmall.constant.MqConst;
import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;

/**
 * 基于插件的  延迟消息  取消订单的
 */
@Configuration
public class OrderCancelConfig {

    //交换机 延迟的交换机 （保存长达2小时以上消息）
    @Bean
    public CustomExchange customExchange(){
        Map<String, Object> arguments  = new HashMap<>();
        arguments.put("x-delayed-type", "direct");
        return new CustomExchange(MqConst.EXCHANGE_DIRECT_ORDER_CANCEL,"x-delayed-message",true,
                false,arguments);
    }

    //
    @Bean
    public Queue queue12(){
        return QueueBuilder.durable(MqConst.QUEUE_ORDER_CANCEL).build();
    }

    @Bean
    public Binding bindingQueue12ToCustomExchange(){
        return BindingBuilder.bind(queue12()).to(customExchange()).
                with(MqConst.ROUTING_ORDER_CANCEL).noargs();
    }
}
